package dabs.engine.plant;

import dabs.engine.control.ComponentCommand;
import dabs.engine.environment.*;
import dabs.engine.messaging.Notification;
import dabs.engine.messaging.NotificationHandler;

public class Reactor extends Converter implements AcceptsModifier{
	private static final long serialVersionUID = 9103067283645337784L;
	
	private double rodLevel;
	
	public Reactor(NotificationHandler mailBox, String name, double rodLevel) {
		super(mailBox, name, rodLevel);
		this.rodLevel = rodLevel;
	}
	
	public double getRodLevel() { return rodLevel; }
	
	public void setRodLevel(int rodLevel) { 
		if (isDeactivated() == false){ 
			this.rodLevel = rodLevel;
			passMessage(new Notification(getName(), "Rods set to " + rodLevel + "%."));
		}
		else { 
			passMessage(new Notification("Reactor", 
					"Rod's have stalled."));
		}
	}
	
	@Override
	protected void inactivatedModifier(Modifier modifier) {
		super.inactivatedModifier(modifier);
		if (modifier instanceof TemporaryDisable) {
			passMessage(new Notification(getName(), "is now active again"));
		}
	}
	
	@Override
	public void tick() {
		getNewHydroState().update(getConversionRate(), false, getOutputs());
		super.tick();
	}

	@Override
	public void runCommand(ComponentCommand command) {
		assert(command.getDestination().equals(getName()));
		int newLevel = Integer.parseInt(command.getArguments().get(0)); //Line to be changed depending on arguments.
		if (newLevel <= 100 && newLevel >= 0){
			setRodLevel(newLevel);
		}
		else{
			passMessage(new Notification(getName(), "Rods must be set to a value between 0 and 100"));
		}
	}
	
}
